package com.applet.system.controller.istp;

import com.applet.code.util.Page;
import com.applet.system.entity.GeneVo;
import com.applet.system.entity.HttpResult;

import com.applet.system.entity.ProjectCategory;
import com.applet.system.service.IstpManagerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import com.applet.system.service.ActionService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/api")
public class IstpManagerController {

	@Autowired
	private ActionService actionServiceImpl;
	@Autowired
    private IstpManagerService istpManagerService;
	
    /**
     * 微服务中调用:API权限验证
     * @param userId
     * @param url
     * @return
     */
    @GetMapping(value="/validateUrl")
    public HttpResult validateUrl(Long userId, String url) {
    	return new HttpResult(this.actionServiceImpl.validateUrl(userId, url));
    }
    @GetMapping("/getAllUser")
    public HttpResult getAllUser(Page page, GeneVo geneVo) {
        page.initPagingData(Map.class);
        return new HttpResult(page.setResult(this.istpManagerService.getAllUser(page,geneVo)));
    }
    @PostMapping("/addCategory")
    HttpResult addCategory(ProjectCategory category){
        istpManagerService.addCategory(category);
        return HttpResult.OK;
    }
    @PostMapping("/updateCategory")
    HttpResult updateCategory(ProjectCategory category){
        istpManagerService.updateCategory(category);
        return HttpResult.OK;
    }
    @PostMapping("/deleteCategory")
    HttpResult deleteCategory(@RequestParam("ids[]")  List<Long> ids){
        istpManagerService.deleteCategory(ids);
        return HttpResult.OK;
    }
    @GetMapping("/getAllCategorys")
    HttpResult getAllCategorys(Page page){
    page.initPagingData(ProjectCategory.class);
    return new HttpResult(page.setResult(istpManagerService.getAllCategorys()));
    }
    @PostMapping("/getCategorysById")
    HttpResult getCategorysById(@RequestParam("id")  Long id){
        return new HttpResult(istpManagerService.getCategorysById(id));
    }
    @GetMapping("/getProjectList")
    HttpResult getProjectList(Page page,GeneVo geneVo){
        page.initPagingData(Map.class);
        return new HttpResult(page.setResult(istpManagerService.getProjectList(geneVo)));
    }
    @PostMapping("/updateStatusByProjectId")
    HttpResult updateStatusByProjectId(@RequestBody GeneVo geneVo){
        istpManagerService.updateStatusByProjectId(geneVo);

        return  HttpResult.OK;
    }
}
